
public class chenbing {
    private static class Node {
        Node next;
        int num;
        public Node(int num){
            this.num = num;
        }

        public int getNum() {
            return num;
        }
    }

    public static void main(String[] args){
        int totalN = 11;
        int killM = 5;
        //建立链表
        Node head = new Node(1);
        Node next = head;
        for (int i=2;i<=totalN;i++){
            Node tmp = new Node(i);
            next.next = tmp;
            next = tmp;
        }
        next.next = head;



        int count = 1;
        //当前人
        Node current = head;
        //前一个人
        Node perNode = null;

        while (current.next !=current){
            if (count == killM){
                count =1;
                current = current.next;
                perNode.next = current;
            }else {
                count ++;
                perNode = current;
                current = current.next;
            }
        }

        System.out.println("留下来的人员序号-----" + current.getNum());
    }
}
